package v;

import core.constructor.constructor;
import tools.DatosComboBox;
import c.AcuedienteController;
import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import org.apache.commons.lang3.StringEscapeUtils;
import org.jdesktop.swingx.JXDatePicker;
import org.jdesktop.swingx.JXMonthView;
import org.jdesktop.swingx.plaf.basic.BasicCalendarHeaderHandler;
import org.jdesktop.swingx.plaf.basic.CalendarHeaderHandler;
import org.jdesktop.swingx.plaf.basic.SpinningCalendarHeaderHandler;
import tools.Util;

/**
 *
 * @author !gaso
 */
public class Acudiente_View_Add extends javax.swing.JPanel {

    constructor c;
    AcuedienteController controlador;
    DatosComboBox cbx;
    //Modo en que se debe de desplegar la Interfaz - INSERT - UPDATE - SELECT
    private String mod = "";
    private String llavePrimaria;
    //Corresponde al Nombre del Campo en la Base de Datos que es LlavePrimaria
    private String campoPK;
    private String noIdentificacion = "";

    public Acudiente_View_Add() {
    }

    public Acudiente_View_Add(Object... e) {
        initComponents();
        controlador = new AcuedienteController();
        config(e);
        //prepararTransaccion();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        cIdentificacion = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        cNombres = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cApellidos = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        cDireccion = new javax.swing.JTextField();
        cTelefono = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        cOcupacion = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        cbSexo = new javax.swing.JComboBox();
        cbDepto = new javax.swing.JComboBox();
        bGuardar = new javax.swing.JButton();
        bClear = new javax.swing.JButton();
        bCancelar = new javax.swing.JButton();
        jXTitledSeparator1 = new org.jdesktop.swingx.JXTitledSeparator();
        jXTitledSeparator2 = new org.jdesktop.swingx.JXTitledSeparator();
        jXTitledSeparator3 = new org.jdesktop.swingx.JXTitledSeparator();
        cbCiudad = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        cFecha = new org.jdesktop.swingx.JXDatePicker();
        jLabel11 = new javax.swing.JLabel();
        cbTipoDocumento = new javax.swing.JComboBox();

        setMinimumSize(new java.awt.Dimension(403, 371));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Numero Identificación");

        cIdentificacion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Nombres");

        cNombres.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setText("Apellidos");

        cApellidos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Direccion");

        cDireccion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        cTelefono.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Telefono");

        cOcupacion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("Fecha Nacimiento");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setText("Depto Residencia");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setText("Ocupación");

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel9.setText("Sexo");

        cbSexo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        cbDepto.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbDepto.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbDeptoItemStateChanged(evt);
            }
        });

        bGuardar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        bGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/guardar32.png"))); // NOI18N
        bGuardar.setText("Guardar");
        bGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGuardarActionPerformed(evt);
            }
        });

        bClear.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        bClear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/limpiar32.png"))); // NOI18N
        bClear.setText("Limpiar Campos");
        bClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bClearActionPerformed(evt);
            }
        });

        bCancelar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        bCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/cancelar32.png"))); // NOI18N
        bCancelar.setText("Cancelar");
        bCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCancelarActionPerformed(evt);
            }
        });

        jXTitledSeparator1.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        jXTitledSeparator1.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jXTitledSeparator1.setTitle("Datos Generales");

        jXTitledSeparator2.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        jXTitledSeparator2.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jXTitledSeparator2.setTitle("Datos Ubicación");

        jXTitledSeparator3.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        jXTitledSeparator3.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jXTitledSeparator3.setTitle("Otros Datos");

        cbCiudad.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel10.setText("Ciudad Residencia");

        cFecha.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cFecha.setFormats("dd-MM-yyyy");
        cFecha.setAutoscrolls(true);
        cFecha.setDoubleBuffered(true);
        cFecha.setInheritsPopupMenu(true);

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel11.setText("Tipo Documento");

        cbTipoDocumento.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbTipoDocumento.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbTipoDocumentoItemStateChanged(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jXTitledSeparator2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(layout.createSequentialGroup()
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(jLabel5)
                                        .add(jLabel4)
                                        .add(jLabel7))
                                    .add(35, 35, 35)
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(cDireccion)
                                        .add(cTelefono)
                                        .add(cbDepto, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .add(layout.createSequentialGroup()
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(jLabel3)
                                        .add(jLabel1)
                                        .add(jLabel2)
                                        .add(jLabel11))
                                    .add(12, 12, 12)
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(cbTipoDocumento, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .add(cIdentificacion)
                                        .add(cNombres)
                                        .add(org.jdesktop.layout.GroupLayout.TRAILING, cApellidos))))
                            .add(34, 34, 34))
                        .add(layout.createSequentialGroup()
                            .add(jXTitledSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(172, 172, 172))
                        .add(layout.createSequentialGroup()
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(layout.createSequentialGroup()
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(jLabel9)
                                        .add(jLabel6)
                                        .add(jLabel8))
                                    .add(35, 35, 35)
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(cOcupacion)
                                        .add(cbSexo, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .add(cFecha, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .add(jXTitledSeparator3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(layout.createSequentialGroup()
                                    .add(jLabel10)
                                    .add(31, 31, 31)
                                    .add(cbCiudad, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .add(34, 34, 34)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(bGuardar)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(bClear)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(bCancelar)
                        .add(46, 46, 46))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(jXTitledSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel11)
                    .add(cbTipoDocumento, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel1)
                        .add(9, 9, 9)
                        .add(jLabel2)
                        .add(12, 12, 12)
                        .add(jLabel3))
                    .add(layout.createSequentialGroup()
                        .add(cIdentificacion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(6, 6, 6)
                        .add(cNombres, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cApellidos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jXTitledSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(12, 12, 12)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel4)
                        .add(12, 12, 12)
                        .add(jLabel5)
                        .add(17, 17, 17)
                        .add(jLabel7))
                    .add(layout.createSequentialGroup()
                        .add(cDireccion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(6, 6, 6)
                        .add(cTelefono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(11, 11, 11)
                        .add(cbDepto, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel10)
                    .add(cbCiudad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jXTitledSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(3, 3, 3)
                        .add(jLabel6)
                        .add(9, 9, 9)
                        .add(jLabel8)
                        .add(14, 14, 14)
                        .add(jLabel9))
                    .add(layout.createSequentialGroup()
                        .add(cFecha, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cOcupacion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(6, 6, 6)
                        .add(cbSexo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(bGuardar)
                    .add(bClear)
                    .add(bCancelar))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void bGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGuardarActionPerformed
    prepararTransaccion();
}//GEN-LAST:event_bGuardarActionPerformed

private void cbDeptoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbDeptoItemStateChanged
    //Evento que afecta Combobox de Ciudades iniciado por ComboBox Departamentos
    cbCiudad.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbCiudad(cbDepto)));
}//GEN-LAST:event_cbDeptoItemStateChanged

private void cbTipoDocumentoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbTipoDocumentoItemStateChanged
// TODO add your handling code here:
}//GEN-LAST:event_cbTipoDocumentoItemStateChanged

    private void bCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelarActionPerformed
        if (c != null) {
            c.ventPrincipal();
        } else {
            Logger.getLogger(Acudiente_View_Add.class.getName()).log(Level.WARNING, "La Clase Constructor no ha sido instanciada");
        }
    }//GEN-LAST:event_bCancelarActionPerformed

    private void bClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bClearActionPerformed
        Util.limpiarCamposForm(this);
    }//GEN-LAST:event_bClearActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bCancelar;
    private javax.swing.JButton bClear;
    private javax.swing.JButton bGuardar;
    private javax.swing.JTextField cApellidos;
    private javax.swing.JTextField cDireccion;
    private org.jdesktop.swingx.JXDatePicker cFecha;
    private javax.swing.JTextField cIdentificacion;
    private javax.swing.JTextField cNombres;
    private javax.swing.JTextField cOcupacion;
    private javax.swing.JTextField cTelefono;
    private javax.swing.JComboBox cbCiudad;
    private javax.swing.JComboBox cbDepto;
    private javax.swing.JComboBox cbSexo;
    private javax.swing.JComboBox cbTipoDocumento;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator1;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator2;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator3;
    // End of variables declaration//GEN-END:variables

    /**
     * <strong>config</strong><br> Configura los parametros que provienen del
     * constructor de la clase.<br> e[0] - contiene el JFrame 'padre'.</br> e[1]
     * - Modo de Presentacion de la Interfaz (INSERT / UPDATE / SELECT).</br>
     * e[2] - contiene el JFrame 'padre'.</br>
     *
     * @param e
     */
    private void config(Object... e) {
        if (e.length > 0) {
            try {

                cbx = new DatosComboBox();
                cbDepto.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbDepartamento()));
                cbDepto.setSelectedItem("Valle del Cauca");
                cbCiudad.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbCiudad(cbDepto)));
                cbSexo.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbSexo()));
                cbTipoDocumento.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbTipoDocumento()));

                c = (constructor) e[0];

                //Setear Migas de Pan
                c.setNavegar("Acudiente_View_Grid");

                // Indicar a las 'migas de pan' donde estamos.
                c.setLabelModulo("Acudientes");

                //Configura la Interfaz para el Modo en el que fue invocado
                configModo((String) e[1], (String) e[2]);


            } catch (Exception exc) {
                System.err.println("(config())Error de Asignacion , compruebe el numero de Parametros que envia .. " + exc.getMessage());
                exc.printStackTrace();
            }
        }



        System.out.println("getLlavePrimaria() = " + getLlavePrimaria());




        //Personalizar Campos de Fecha
        //cFecha.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

    }

    void prepararTransaccion() {
        //Herramientas
        tools.Util u = new tools.Util();
        String tablaBD = "acudiente";

//        
//        tabla = "identificacion=55[req-num(0,20)]";



        StringBuilder sqlAndRestricciones = new StringBuilder();
        StringBuilder camposBD = new StringBuilder();
        StringBuilder valoresBD = new StringBuilder();

        sqlAndRestricciones.append("Tipo Identificacion@id_tipodocumento='" + cbx.getKeyTipoDocumento(cbTipoDocumento) + "'[req-txt(6,10)]&");
        sqlAndRestricciones.append("Numero Identificacion@identificacion='" + cIdentificacion.getText().toLowerCase() + "'[req-num(0,20)UNQ" + noIdentificacion + "]&");
        sqlAndRestricciones.append("Nombre Acudiente@nombres='" + cNombres.getText().toLowerCase() + "'[req-txt(0,0)]&");
        sqlAndRestricciones.append("Apellido Acudiente@apellidos='" + cApellidos.getText().toLowerCase() + "'[req-txt(0,0)]&");
        sqlAndRestricciones.append("Direccion Acuediente@direccion='" + StringEscapeUtils.escapeEcmaScript(cDireccion.getText().toLowerCase()) + "'[-(0,80)]&");
        sqlAndRestricciones.append("Numero de Telefono@telefono=" + cTelefono.getText().toLowerCase().trim() + "[-num(7,13)&]");
        sqlAndRestricciones.append("Ciudad Residencia@id_ciudad=" + cbx.getKeyMun(cbCiudad) + "[-num(1,13)]&");
        sqlAndRestricciones.append("Fecha Nacimiento@fecha_nacimiento=" + u.fechaToString(cFecha.getDate(), true) + "[req-fecha(0,0)]&");
        sqlAndRestricciones.append("Ocupación@ocupacion='" + cOcupacion.getText().toLowerCase() + "'[-(0,70)]&");
        sqlAndRestricciones.append("Sexo@id_sexo='" + cbx.getKeySexo(cbSexo) + "'[-txt(1,13)]");


        String mensajeUsuario = controlador.prepararTransaccion(tablaBD, sqlAndRestricciones, mod, "El Acudiente", campoPK);

        c.informarUsuario(mensajeUsuario);

        //Asignar el Nuevo valor al Campo Identificacion (Unique Campos)
        noIdentificacion = cIdentificacion.getText().toLowerCase();
    }

    private void configModo(String m, String key) {
        mod = m;
        String SQL_BUSCAR = "SELECT id_acudiente , td.descripcion ,identificacion as identificacion, nombres as nombres , apellidos as apellidos, direccion as direccion, telefono as telefono , depto.nombre_dep , c.nombre_ciudad , a.fecha_nacimiento , a.ocupacion , s.descripcion"
                + " FROM acudiente a  , tipodocumento td , departamentos depto , ciudad c, sexo s"
                + " WHERE a.id_tipodocumento = td.id_tipodocumento AND a.id_ciudad = c.id_ciudad AND c.id_depto = depto.id_departamento AND a.id_sexo = s.id_sexo"
                + " AND id_acudiente = " + key;
        if (!mod.equals("")) {

            if ("INSERT".equals(mod)) {
                c.setLabelAccion("Agregar Acudiente");
            }

            if (!mod.equals("INSERT")) {
                setLlavePrimaria(key);
                //c.setLabelAccion("Crear Acudiente Paciente");
                campoPK = "id_acudiente = " + getLlavePrimaria();

            }

            if (mod.equals("SELECT")) {
                System.out.println("mod = " + mod);
                System.out.println("key = " + key);
                estadoComponentes(false);
                c.setLabelAccion("Consulta Acudiente Paciente");
                setAcudiente(controlador.buscar(SQL_BUSCAR));

            } else if (mod.equals("UPDATE")) {
                System.out.println("mod = " + mod);
                System.out.println("key = " + key);

                estadoComponentes(true);

                c.setLabelAccion("Modiciar Acudiente Paciente");
                setAcudiente(controlador.buscar(SQL_BUSCAR));
                bGuardar.setText("Actualizar");
                //Cambiar icono here...

                //Tomar cuando arranque la pantalla los campos UNQ
                noIdentificacion = cIdentificacion.getText();
                System.out.println("noIdentificacion = " + noIdentificacion);
            }

        }
    }

    public String getLlavePrimaria() {
        return llavePrimaria;
    }

    public void setLlavePrimaria(String llavePrimaria) {
        this.llavePrimaria = llavePrimaria;
    }

    void estadoComponentes(Boolean estado) {
        cbTipoDocumento.setEnabled(estado);
        cIdentificacion.setEditable(estado);
        cNombres.setEditable(estado);
        cApellidos.setEditable(estado);
        cDireccion.setEditable(estado);
        cTelefono.setEditable(estado);
        cbDepto.setEnabled(estado);
        cbCiudad.setEnabled(estado);
        cFecha.setEditable(estado);
        cOcupacion.setEditable(estado);
        cbSexo.setEnabled(estado);

        bGuardar.setVisible(estado);
        bClear.setVisible(estado);
    }

    private void setAcudiente(Object[][] acudiente) {

        //Herramientas
        tools.Util u = new tools.Util();

        System.out.println("Tamaño acuediente " + acudiente.length);

//        for (int i = 0; i < acudiente[0].length ; i++) {
//            System.out.println("Dato => " + acudiente[0][i]);
//        }
        cbTipoDocumento.setSelectedItem(acudiente[0][1].toString());
        cIdentificacion.setText(acudiente[0][2].toString());
        cNombres.setText(acudiente[0][3].toString());
        cApellidos.setText(acudiente[0][4].toString());
        cDireccion.setText(acudiente[0][5].toString());
        cTelefono.setText(acudiente[0][6].toString());
        cbDepto.setSelectedItem(acudiente[0][7].toString());
        cbCiudad.setSelectedItem(acudiente[0][8].toString());
        cFecha.setDate(u.stringToDate(acudiente[0][9].toString())); //SELECT fecha_nacimiento::date FROM acudiente;
        cOcupacion.setText(acudiente[0][10].toString());
        cbSexo.setSelectedItem(acudiente[0][11].toString());


    }
}
